
package com.gitee.jmash.storage.entity;


import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;
import com.gitee.jmash.core.orm.jpa.entity.OrderBy;
import com.gitee.jmash.storage.entity.StorageOrganUserEntity.StorageOrganUserPk;
import jakarta.json.bind.annotation.JsonbTransient;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.validation.constraints.NotNull;

/**
 * storage 表 .
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
@Entity
@Table(name = "storage_organ_user")
@IdClass(StorageOrganUserPk.class)
public class StorageOrganUserEntity implements OrderBy<StorageOrganUserPk> {

  private static final long serialVersionUID = 1L;

  /** 统一身份ID. */
  private String unifiedId;
  /** 组织ID. */
  private UUID organId = UUID.randomUUID();
  /** 排序. */
  private Integer orderBy;

  /**
   * 默认构造函数.
   */
  public StorageOrganUserEntity() {
    super();
  }

  /** 实体主键. */
  @Transient
  @JsonbTransient
  public StorageOrganUserPk getEntityPk() {
    StorageOrganUserPk pk = new StorageOrganUserPk();
    pk.setUnifiedId(this.unifiedId);
    pk.setOrganId(this.organId);
    return pk;
  }

  /** 实体主键. */
  public void setEntityPk(StorageOrganUserPk pk) {
    this.unifiedId = pk.getUnifiedId();
    this.organId = pk.getOrganId();
  }

  /** 统一身份ID(UnifiedId). */
  @Id

  @Column(name = "unified_id", nullable = false)
  public String getUnifiedId() {
    return unifiedId;
  }

  /** 统一身份ID(UnifiedId). */
  public void setUnifiedId(String unifiedId) {
    this.unifiedId = unifiedId;
  }

  /** 组织ID(OrganId). */
  @Id
  @Column(name = "organ_id", nullable = false, columnDefinition = "BINARY(16)")
  public UUID getOrganId() {
    return organId;
  }

  /** 组织ID(OrganId). */
  public void setOrganId(UUID organId) {
    this.organId = organId;
  }

  /** 排序(OrderBy). */

  @Column(name = "order_by", nullable = false)
  public Integer getOrderBy() {
    return orderBy;
  }

  /** 排序(OrderBy). */
  public void setOrderBy(Integer orderBy) {
    this.orderBy = orderBy;
  }

  @Override
  public int hashCode() {
    return Objects.hash(unifiedId, organId);
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }

    StorageOrganUserEntity other = (StorageOrganUserEntity) obj;

    return Objects.equals(unifiedId, other.unifiedId) && Objects.equals(organId, other.organId);
  }


  /**
   * StorageOrganUserPK（直接对应数据库的配置 由生成工具产生）.
   *
   * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
   */
  @Embeddable
  public static class StorageOrganUserPk implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 统一身份ID. */
    @NotNull
    private String unifiedId;
    /** 组织ID. */
    @NotNull
    private UUID organId;
    
    public StorageOrganUserPk() {
      super();
    }

    public StorageOrganUserPk(String unifiedId,UUID organId) {
      super();
      this.unifiedId = unifiedId;
      this.organId = organId;
    }

    /** 统一身份ID(UnifiedId). */
    @Column(name = "unified_id", nullable = false)
    public String getUnifiedId() {
      return unifiedId;
    }

    /** 统一身份ID(UnifiedId). */
    public void setUnifiedId(String unifiedId) {
      this.unifiedId = unifiedId;
    }

    /** 组织ID(OrganId). */
    @Column(name = "organ_id", nullable = false)
    public UUID getOrganId() {
      return organId;
    }

    /** 组织ID(OrganId). */
    public void setOrganId(UUID organId) {
      this.organId = organId;
    }

    @Override
    public int hashCode() {
      return Objects.hash(unifiedId, organId);
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (obj == null) {
        return false;
      }
      if (getClass() != obj.getClass()) {
        return false;
      }
      StorageOrganUserPk other = (StorageOrganUserPk) obj;
      return Objects.equals(unifiedId, other.unifiedId) && Objects.equals(organId, other.organId);
    }
  }

}
